package mof.gov.dmdc.view.backing.lov;

import java.util.Iterator;
import java.util.List;

import mof.gov.dmdc.view.common.Common;

import oracle.adf.view.rich.component.rich.data.RichTable;

import mof.gov.dmdc.model.applicationmodule.lovModuleImpl;

import oracle.jbo.Row;
import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;

import org.apache.myfaces.trinidad.model.RowKeySet;

public class LovBean {

    private String tinhSearch;
    private List listTinh;
    private String huyenSearch;
    private List huyenList;
    private RichTable table;

    public void setTinhSearch(String tinhSearch) {
        this.tinhSearch = tinhSearch;
    }

    public String getTinhSearch() {
        return tinhSearch;
    }

    public void setListTinh(List listTinh) {
        this.listTinh = listTinh;
    }

    public List getListTinh() {
        return listTinh;
    }

    public void setHuyenSearch(String huyenSearch) {
        this.huyenSearch = huyenSearch;
    }

    public String getHuyenSearch() {
        return huyenSearch;
    }

    public void setHuyenList(List huyenList) {
        this.huyenList = huyenList;
    }

    public List getHuyenList() {
        return huyenList;
    }

    public void setTable(RichTable table) {
        this.table = table;
    }

    public RichTable getTable() {
        return table;
    }

    public String cancelAction() {
        Common.putToPageFlowScope("isSelect", "false");
        return "return";
    }

    public String selectAction() {
        RowKeySet rowKeySet = getTable().getSelectedRowKeys();
        Iterator iterator = rowKeySet.iterator();
        if (iterator.hasNext()) {
            Object key = iterator.next();
            table.setRowKey(key);
            Object o = table.getRowData();
            JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)o;
            Row row = rowData.getRow();
            Common.putToPageFlowScope("isSelected", "true");
            Object selectedValue = row.getAttribute(0);
            Common.putToPageFlowScope("selectedValue", selectedValue);
        }
        return "return";
    }

    public void initLovPage() {
        String lovName = "";
        try {
            lovName = Common.getFromPageFlowScope("lovName").toString();
        } catch (NullPointerException e) {
            System.out.println("Khong nhan duoc lovName");
        }
        lovModuleImpl am = (lovModuleImpl)Common.getAppModuleForDataControl("lovModuleDataControl");
        am.createLovViewObject(lovName);
    }
}
